package cn.xfdzx.android.apps.shop.presenter;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.MesCenterListBean;
import cn.xfdzx.android.apps.shop.contract.MessageCenterContract;
import cn.xfdzx.android.apps.shop.model.MessageTypeModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * @author f.zheng
 * @date 2020/10/21.
 * Description：
 */
public class MessageTypePresenter extends BasePresenter<MessageCenterContract.View> implements MessageCenterContract.Presenter {

    private MessageCenterContract.Model model;

    public MessageTypePresenter() {
        model = new MessageTypeModel();
    }

    @Override
    public void getMesTypeList() {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getMesTypeList()
                .compose(RxScheduler.<MesCenterListBean>Flo_io_main())
                .as(mView.<MesCenterListBean>bindAutoDispose())
                .subscribe(new Consumer<MesCenterListBean>() {
                    @Override
                    public void accept(MesCenterListBean bean) throws Exception {
                        mView.getMesTypeList(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
}
